namespace SCIENEW {
    /// <summary>
    /// 矿物数据库，储存矿物伴生矿、生成概率等等
    /// </summary>
    public static class OresDataBase {
        static readonly Dictionary<Materials, List<(Materials Ore, float Probability)>> companionOresMap;
        static readonly Dictionary<Materials, float> mineralProbabilities;

        static OresDataBase() {

            companionOresMap = new Dictionary<Materials, List<(Materials, float)>>();
            companionOresMap.Add(Materials.Gold, new List<(Materials, float)> { (Materials.Silver, 0.3f), (Materials.Mercury, 0.1f) });
            companionOresMap.Add(Materials.Silver, new List<(Materials, float)> { (Materials.Gold, 0.1f), (Materials.Copper, 0.3f) });
            companionOresMap.Add(Materials.Platinum, new List<(Materials, float)> { (Materials.Nickel, 0.4f), (Materials.Iron, 0.2f) });
            companionOresMap.Add(Materials.Lead, new List<(Materials, float)> { (Materials.Zinc, 0.5f) });
            companionOresMap.Add(Materials.Zinc, new List<(Materials, float)> { (Materials.Lead, 0.5f), (Materials.Copper, 0.3f) });
            companionOresMap.Add(Materials.Stannary, new List<(Materials, float)> { (Materials.Lead, 0.6f) });
            companionOresMap.Add(Materials.Mercury, new List<(Materials, float)> { (Materials.Gold, 0.1f) });
            companionOresMap.Add(Materials.Chromium, new List<(Materials, float)> { (Materials.Iron, 0.3f) });
            companionOresMap.Add(Materials.Titanium, new List<(Materials, float)> { (Materials.Iron, 0.3f) });
            companionOresMap.Add(Materials.Nickel, new List<(Materials, float)> { (Materials.Platinum, 0.1f), (Materials.Copper, 0.3f) });
            companionOresMap.Add(Materials.Uranium, new List<(Materials, float)> { (Materials.Phosphorus, 0.3f) });
            companionOresMap.Add(Materials.Phosphorus, new List<(Materials, float)> { (Materials.Titanium, 0.2f) });

            mineralProbabilities = new Dictionary<Materials, float>
            {
                { Materials.Gold, 0.2f },
                { Materials.Silver, 0.65f },
                { Materials.Platinum, 0.23f },
                { Materials.Lead, 2.25f },
                { Materials.Zinc, 2.7f },
                { Materials.Stannary, 1.75f },
                { Materials.Mercury, 0.73f },
                { Materials.Chromium, 3.05f },
                { Materials.Titanium, 5f },
                { Materials.Nickel, 2.9f },
                { Materials.Uranium, 1.9f },
                { Materials.Phosphorus, 4.3f }
            };
        }

        /// <summary>
        /// 获取矿物伴生矿
        /// </summary>
        /// <param name="primaryOre"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public static List<(Materials Ore, float Probability)> GetCompanionOres(Materials primaryOre) {
            if (companionOresMap.TryGetValue(primaryOre, out List<(Materials Ore, float Probability)>? ores)) {
                return ores;
            }
            throw new ArgumentException($"Companion ores for {primaryOre} not found.");
        }

        /// <summary>
        /// 获取矿物生成概率
        /// </summary>
        /// <param name="ore"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public static float GetOreProbability(Materials ore) {
            if (mineralProbabilities.TryGetValue(ore, out float probability)) {
                return probability;
            }
            throw new ArgumentException($"Companion ores for {mineralProbabilities} not found.");
        }
    }
}